<meta charset="UTF-8">
<input id="kw" placeholder="搜索词" />
<input type="button" value="搜索" onclick="search()" />

<div id="jddata">

</div>
<script>
    //https://api.douban.com/v2/movie/in_theaters?callback=dbdata
    function search(){
        var jdscripts = document.getElementsByClassName("jdscript");

        for(var i=0;i<jdscripts.length;i++){
            jdscripts[i].parentNode.removeChild(jdscripts[i]);
        }

        jddata.innerHTML = "";
        var jdjs = document.createElement("script");
        jdjs.className = "jdscript";
        jdjs.src = "https://x.jd.com/Search?callback=getjddata&area=1&enc=utf-8&keyword="+kw.value
            +"&adType=7&page=1&ad_ids=291%3A33&xtest=new_search&_=1516094140760";
        document.body.appendChild(jdjs);
    }

    function getjddata(data){
        var datas;
        for(var d in data){
            datas = data[d];
        }

        for(var i=0;i<datas.length;i++){
            var d = datas[i];
            var newp = document.createElement("p");
            newp.innerHTML = d.ad_title;
            jddata.appendChild(newp);
        }
    }
</script>

<script class="jdscript" src="https://x.jd.com/Search?callback=getjddata&area=1&enc=utf-8&keyword=iphone&adType=7&page=2&ad_ids=291%3A33&xtest=new_search&_=1516094140760"></script>

<script>
    //Ajax

   function test(){
       //1.声明异步请求对象
       var xmlhttp = new XMLHttpRequest();
       //2.设置请求地址
       xmlhttp.open("GET","http://www.baidu.com",true);
       //3.发送请求
       xmlhttp.send();
       //4.处理响应
       //xmlhttp 有五个状态
       xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState==4&&xmlhttp.status==200){
            alert(xmlhttp.responseText);
        }
       };
   }
</script>
